import { createApp } from 'vue'
import router from './router'
import store from './store'
import axios from 'axios'

import App from './App.vue'

axios.defaults.baseURL = 'http://localhost:7001/api/'
axios.interceptors.request.use(config => {
  console.log(0)

  store.commit('setLoading', true)
  store.commit('setError', { status: false, message: '' })
  return config
})
axios.interceptors.response.use(config => {
  console.log(8)

  setTimeout(() => {
    store.commit('setLoading', false)
  }, 1000)
  return config
}, e => {
  console.log('服务器响应错误')

  if (e && e.response && e.response.data) {
    const { error } = e.response.data
    store.commit('setError', { status: true, message: error })
    store.commit('setLoading', false)
    return Promise.reject(e.response.data)
  } else {
    store.commit('setError', { status: true, message: e })
    store.commit('setLoading', false)
    return Promise.reject(e)
  }
})

const app = createApp(App)
app.use(router)
app.use(store)
app.mount('#app')
